﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DACU.UserControls
{
	/// <summary>
	/// Логика взаимодействия для RunningString.xaml
	/// </summary>
	public partial class RunningString : UserControl
	{
		private double _timer = 2;
		public double Timer
		{
			get { return _timer; }
			set { _timer = value; }
		}

		public string Text
		{
			get { return tbmarquee.Text; }
			set { tbmarquee.Text = value; }
		}

		public RunningString()
		{
			InitializeComponent();
		}

		public void LeftToRightMarquee()
		{
			double height = cMain.ActualHeight - tbmarquee.ActualHeight;
			tbmarquee.Margin = new Thickness(0, height / 2, 0, 0);
			var doubleAnimation = new DoubleAnimation
			                                  	{
			                                  		From = -tbmarquee.ActualWidth,
			                                  		To = cMain.ActualWidth,
			                                  		RepeatBehavior = RepeatBehavior.Forever,
													Duration = new Duration(TimeSpan.FromSeconds(_timer))
			                                  	};
			tbmarquee.BeginAnimation(Canvas.LeftProperty, doubleAnimation);
		}

		public void RightToLeftMarquee()
		{
			double height = cMain.ActualHeight - tbmarquee.ActualHeight;
			tbmarquee.Margin = new Thickness(0, height / 2, 0, 0);
			var doubleAnimation = new DoubleAnimation
			                                  	{
			                                  		From = -tbmarquee.ActualWidth,
			                                  		To = cMain.ActualWidth,
			                                  		RepeatBehavior = RepeatBehavior.Forever,
													Duration = new Duration(TimeSpan.FromSeconds(_timer))
			                                  	};
			tbmarquee.BeginAnimation(Canvas.RightProperty, doubleAnimation);
		}

		public void TopToBottomMarquee()
		{
			double width = cMain.ActualWidth - tbmarquee.ActualWidth;
			tbmarquee.Margin = new Thickness(width / 2, 0, 0, 0);
			var doubleAnimation = new DoubleAnimation
			                                  	{
			                                  		From = -tbmarquee.ActualHeight,
			                                  		To = cMain.ActualHeight,
			                                  		RepeatBehavior = RepeatBehavior.Forever,
													Duration = new Duration(TimeSpan.FromSeconds(_timer))
			                                  	};
			tbmarquee.BeginAnimation(Canvas.TopProperty, doubleAnimation);
		}

		public void BottomToTopMarquee()
		{
			double width = cMain.ActualWidth - tbmarquee.ActualWidth;
			tbmarquee.Margin = new Thickness(width / 2, 0, 0, 0);
			var doubleAnimation = new DoubleAnimation
			                                  	{
			                                  		From = -tbmarquee.ActualHeight,
			                                  		To = cMain.ActualHeight,
			                                  		RepeatBehavior = RepeatBehavior.Forever,
													Duration = new Duration(TimeSpan.FromSeconds(_timer))
			                                  	};
			tbmarquee.BeginAnimation(Canvas.BottomProperty, doubleAnimation);
		}
	}
}
